package refletion;

/**
 * @program: thread
 * @description:
 * @author: gongj
 * @Description: TODO
 * @create: 2020-06-04 20:35
 **/
public class Test3 {
    public static void main(String[] args) throws ClassNotFoundException {

        Person p = new Student();
        System.out.println(p.name);
        //通过对象获得
        Class<? extends Person> aClass = p.getClass();
        System.out.println(aClass.hashCode());

        Student student = new Student();
        Class<? extends Student> aClass1 = student.getClass();
        System.out.println(aClass1.hashCode());

       //通过forName获得
        Class  Clas = Class.forName("refletion.Student");
        System.out.println(Clas.hashCode());

        //通过类名.class
        Class<Student> studentClass = Student.class;
        System.out.println(studentClass.hashCode());

        //基本内置类型的包装类都有一个Type属性
        Class<Integer> type = Integer.TYPE;
        System.out.println(type);
        //获得父类类型
        Class<?> superclass = aClass.getSuperclass();
        System.out.println(superclass.hashCode() + "===" + superclass);
    }
}
class Person{
    public String name;

}
class Student extends Person{

    public Student() {
        this.name = "龚杰";
    }

}

class Tea extends Person {
  public Tea() {
        this.name = "老师";
    }
}